/*
 * IPS114.c
 *
 *  Created on: Jun 19, 2021
 *      Author: huangdou
 */

#include "IPS114.h"
uint8 ips_update_flag;
void ips_init(){
    ips114_init();
//    timer_pit_interrupt_ms(TIMER_3, 100);
}


void show_pic(){
    ips114_displayimage7725((uint8 *)ov7725_uart_image_bin, OV7725_UART_W, OV7725_UART_H);
}

void show_speed(){
    show_int("LU:", motor[1].curSpeed, INFO_AREA_X, 1);
    show_int("RU:", motor[2].curSpeed, INFO_AREA_X, 2);
    show_int("LD:", motor[3].curSpeed, INFO_AREA_X, 3);
    show_int("LD:", motor[4].curSpeed, INFO_AREA_X, 4);

}

void show_curv(){
    show_float("LC:", get_curvature(img_info.l_curve_out_point, LPOS, 2, 2), INFO_AREA_X, 2);
    show_float("RC:", get_curvature(img_info.r_curve_out_point, RPOS, 2, 2), INFO_AREA_X, 3);
}

void show_point(){
    show_int("LDC:", img_info.l_down_corner, 1, 5);
    show_int("LUC:", img_info.l_up_corner, INFO_AREA_X, 5);
    show_int("RUC", img_info.r_up_corner, 1, 6);
    show_int("RDC:", img_info.r_down_corner, INFO_AREA_X, 6);
}

void show_curvature(){
//    show_float("LCURV:", get_curvature(img_info.l_curve_out_point, LPOS), x, y)
}

void show_int(char* desc, int8 data, uint16 x, uint16 y){
    uint8 len = strlen(desc);
    ips114_showstr(x, y, desc);
    ips114_showint8(x + len * WORD_LEN, y, data);
}
void show_float(char* desc, float data, uint16 x, uint16 y){
    uint8 len = strlen(desc);
    ips114_showstr(x, y, desc);
    ips114_showfloat(x + len * WORD_LEN, y, data, 1, 2);
}

void show_string(char* desc, char* data, uint16 x, uint16 y){
    uint8 len = strlen(desc);
    ips114_showstr(x, y, desc);
    ips114_showstr(x + len * WORD_LEN, y, data);
}
void show_diff(){
    show_float("DIFF:", img_info.diff, INFO_AREA_X, DIFF_ORDER);
}

void show_stat(){
    char* stat_desc;
    switch (cur_stat) {
        case STRAIGHT:
            stat_desc = "_STRAIGHT_";
            break;
        case FIND_FORK:
            stat_desc = "_FIND_FORK";
            break;
        case ENTER_FORK:
            stat_desc = "ENTER_FORK";
            break;
        case FIND_RING:
            stat_desc = "_FIND_RING";
            break;
        case ENTER_RING:
            stat_desc = "ENTER_RING";
            break;
        case FIND_CROSS:
            stat_desc = "FIND_CROSS";
            break;
        default:
            stat_desc = "_UNDEFINED";
            break;
    }
    show_string("STAT:", stat_desc, INFO_AREA_X, STAT_ORDER);
}

void show_type(){
    char* l_stat_desc;
    char* r_stat_desc;
    switch (l_road_type) {
        case NORMAL:
            l_stat_desc = "NORMAL";
            break;
        case CURVED_IN:
            l_stat_desc = "CURVED_IN";
            break;
        case CURVED_OUT:
            l_stat_desc = "CURVED_OUT";
            break;
        case JUMP_OUT:
            l_stat_desc = "JUMP_OUT";
            break;
        default:
            l_stat_desc = "UNDEFINED";
            break;
     }
     switch (r_road_type) {
            case NORMAL:
                r_stat_desc = "NORMAL";
                break;
            case CURVED_IN:
                r_stat_desc = "CURVED_IN";
                break;
            case CURVED_OUT:
                r_stat_desc = "CURVED_OUT";
                break;
            case JUMP_OUT:
                r_stat_desc = "JUMP_OUT";
                break;
            default:
                r_stat_desc = "UNDEFINED";
                break;
         }
    show_string("LS:", l_stat_desc, INFO_AREA_X, LS_ORDER);
    show_string("RS:", r_stat_desc, INFO_AREA_X, RS_ORDER);
}

void ips_show_all(){
    display_processed_img();
//    show_speed();
//    ips114_displayimage7725(ov7725_uart_image_bin, MAXC, MAXR);
    show_diff();
    show_stat();
    show_curv();
    show_point();
}
